﻿
        <!-- /. NAV SIDE  -->
        <div id="page-wrapper">
            <div id="page-inner">
                <div class="panel panel-default">
                 
       <div class="col-md-6 col-sm-6 col-xs-12">
               <div class="panel panel-primary">
                        <div class="panel-heading">
                          
                        </div>
                         <form role="form"  enctype="multipart/form-data" method="post" action="">
                        <div class="panel-body">
                          
                          <div class="form-group has-success">
                                            <label class="control-label" for="success" >角色添加</label>
                                            <input name="name" type="text" class="form-control" id="success" />
                                        </div>
                                        <div class="form-group">
                                            <label>是否启用</label>
                                            <div class="radio">
                                                <label>
                                                    <input type="radio" checked="" value="0" id="optionsRadios1" name="status">是
                                                </label>
                                                 <label>
                                                    <input type="radio" checked="" value="1" id="optionsRadios1" name="status">否
                                                </label>
                                            </div>
                                         
                                          
                            <div class="form-group">
                           
                                          
                                <?php foreach($data as $k=>$v){?>

                                        <div class="checkbox">
                                         
                                            <label>
                                                <input type="checkbox" value="<?php echo $v['id'];?>" name="
                                                power[]" class="fuji"><?php echo $v['name'];?>
                                            </label>

                                            <?php foreach($fei as $k=>$ve){?>
                                                <?php if($v['id']==$ve['pid']){?>
                                              
                                                    <label>
                                                        <input type="checkbox" value="<?php echo $ve['id'];?>" name="power[]" class="ziji">
                                                             <?php echo $ve['name'];?>
                                                    </label>
                                                       
                                                <?php } ?>    

                                                       
                                            <?php }?>                                                                          
                                        </div>                                          
                                        <br>
                                        
                                <?php }?>
                                             <input type="checkbox" value="" class="qselect" name="power[]" >
                                            <label>全选/反选</label>
                                            <div>
                                              <input type="submit" name="" value="提交">
                                            </div> 
                                        </div>
                            <hr>
                         
                            </div>
                        </div>
                            </div>
                          </div>
                          </form>
                          </div>
                          </div>

<script src="resources/assets/js/jquery-1.10.2.js"></script>
<script type="text/javascript">
$(function(){
    $(".qselect").click(function(){ 

        if($(this).is(':checked')){ 
            $("input[name='power[]']").prop('checked', true)
        }else{ 
            $("input[name='power[]']").prop('checked', false)
        } 
      
    })
    $(".ziji").click(function(){

           // 获取所有选择框中已经选中状态的个数
            var len = $(this).parent().find(':checkbox:checked').length;
               
               
            // 个数大0
            if(len>0){
                    //$("input[name='power[]']").prop('checked', true)
             // 把最上级的选择框选中
            $(this).parent().parent().find('.fuji').prop('checked',true);

            }else{
                // 把最上级的选择框取消选中
                 $(this).parent().parent().find('.fuji').prop('checked',false);

    }

    })


      $(".fuji").click(function(){ 

        if($(this).is(':checked')){ 
            $(this).parent().parent().find("input[name='power[]']").prop('checked', true)
        }else{ 
            $(this).parent().parent().find("input[name='power[]']").prop('checked', false)
        } 
      
    })

    })

</script>

